<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /**
       * 求数组 arr 中，大于 max 的和
       * @param {number[]} arr
       * @param {number} max
       */
      function sum(arr, max) {
        return arr
          .filter((item) => item > max)
          .reduce((total, item) => {
            return (total += item);
          }, 0);
      }

      console.log(sum([1, 2, 3, 4, 6], 5)); // 6
      console.log(sum([1, 2, 3, 4, 6], 1)); // 15
    </script>
  </body>
</html>
